<?php
namespace Admin\Controller;
use Think\Controller;
//供应商控制器 by chenheyou
class ModuleController extends BaseController {
	
	//2016.4.14 by chenheyou
    public function index(){
        $object=M('Module');
        import('ORG.Util.Page');				//Page类的引入
        $count=$object->where($where)->count(); //获取符合条件的数据总数count
		$Page=new \Org\Util\Page($count, 10);	//实例化page类，传入数据总数和每页显示10条内容
		$show=$Page->show();
		$list=$object->where($where)
		->field('bs_Module.*,b.showname as fname')
		->join('LEFT JOIN bs_Form b ON bs_Module.formid = b.id')
		->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign("page",$show);
        $this->display();
    }
	
	//2016.4.14 by chenheyou
    public function editUI(){
		$Object = M("Module");
        $this->assign('formlist',M('Form')->where($where)->select());
		if(I('get.id')){
			$this->assign('object',$Object->where('id='.I('get.id'))->find());
		}
        $this->display('editUI');
    }
	
	//2016.4.14 by chenheyou
    public function editOperation(){
		$Object = M("Module");   
		$Object->create();
		$id = I('post.id');
		
		if($id){
			//修改
			if($Object->save()){
				$this->success('修改成功',U('index'));
			}else{
				dump($Object->_sql());
				$this->error('修改失败');
			}
		}else{
			//增加
			if($Object->add()){
				$this->success('添加成功',U('index'));
			}else{
				dump($Object->_sql());
				$this->error('添加失败');
			}
		}
    }
	
	//2016.4.14 by chenheyou
    public function removeOperation(){
		$Object = M("Module");
		$id = I('get.id');
		if($Object->delete($id)){
			$this->success('删除成功',U('index'));
		}else{
			dump($Object->_sql());
			$this->error('删除失败');
		}
    }
	
	//2016.4.14 by chenheyou
    public function createRightUI(){
		$Object = M("Module");
		if(I('get.id')){
			$this->assign('object',$Object->where('id='.I('get.id'))->find());
		}
        $this->assign('userlist',M('User')->where($where)->select());
        $this->assign('deplist',M('Department')->where($where)->select());
        $this->display('createRightUI');
    }
	
	//2016.4.14 by chenheyou
    public function createRightOperation(){
		$id = I('post.id');
		if($id){
    		$Object = M("Module");   
    		$Object->create(M("Module")->where('id='.$id)->find());
    		
            $Object->createrightuser=I('post.createrightuser');
            $Object->createrightdep=I('post.createrightdep');
            $Object->createrightall=I('post.createrightall');
            
			//修改
			if($Object->save()){
				$this->success('修改成功',U('index'));
			}else{
				dump($Object->_sql());
				$this->error('修改失败');
			}
		}
    }
	
	//2016.4.14 by chenheyou
    public function showRightUI(){
		$Object = M("Module");
		if(I('get.id')){
			$this->assign('object',$Object->where('id='.I('get.id'))->find());
		}
        $this->assign('userlist',M('User')->where($where)->select());
        $this->assign('deplist',M('Department')->where($where)->select());
        $this->display('showRightUI');
    }
	
	//2016.4.14 by chenheyou
    public function showRightOperation(){
		$id = I('post.id');
		if($id){
    		$Object = M("Module");   
    		$Object->create(M("Module")->where('id='.$id)->find());
    		
            $Object->showrightuser=I('post.showrightuser');
            $Object->showrightdep=I('post.showrightdep');
            $Object->showrightall=I('post.showrightall');
            $Object->showrightcreater=I('post.showrightcreater');
            $Object->showrightcreaterpid=I('post.showrightcreaterpid');
            
			//修改
			if($Object->save()){
				$this->success('修改成功',U('index'));
			}else{
				dump($Object->_sql());
				$this->error('修改失败');
			}
		}
    }
}